home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / circuits / spice2g6.z / spice2g6 / spice / Fortran / alfnum.f < prev    next >
Encoding:
Text File  |  1989-02-03  |  1.3 KB  |  53 lines

  1.       subroutine alfnum(number,string,ipos)
  2.       implicit double precision (a-h,o-z)
  3. c
  4. c     this routine converts number into character form, storing the
  5. c characters in the character array string, beginning with the position
  6. c indicated by ipos.
  7. c
  8. c **** note that the 'ipos' variable is changed to indicate the position
  9. c      of the next unwritten character.  this could clobber constants if
  10. c      ipos is not a variable in the calling program
  11. c
  12.       dimension string(1)
  13.       dimension adigit(10)
  14.       data adigit / 1h0,1h1,1h2,1h3,1h4,1h5,1h6,1h7,1h8,1h9 /
  15.       data aminus / 1h- /
  16. c
  17. c
  18.       num=number
  19. c
  20. c  check for number < 0
  21. c
  22.       if (num.ge.0) go to 10
  23.       num=-num
  24. c...  negative number:  insert minus sign
  25.       call move(string,ipos,aminus,1,1)
  26.       ipos=ipos+1
  27. c
  28. c  convert number one digit at a time, in reverse order
  29. c
  30.    10 istart=ipos
  31.    20 numtmp=num/10
  32.       idigit=num-numtmp*10
  33.       call move(string,ipos,adigit(idigit+1),1,1)
  34.       ipos=ipos+1
  35.       num=numtmp
  36.       if (num.ne.0) go to 20
  37.       istop=ipos-1
  38. c
  39. c  now reverse the order of the digits
  40. c
  41.    30 if (istop.le.istart) go to 40
  42.       call move(tmpdgt,1,string,istart,1)
  43.       call move(string,istart,string,istop,1)
  44.       call move(string,istop,tmpdgt,1,1)
  45.       istart=istart+1
  46.       istop=istop-1
  47.       go to 30
  48. c
  49. c  conversion complete
  50. c
  51.    40 return
  52.       end
  53.